// Copyright (C) 1995
// Use is governed by the MiscKit license

#import "MiscPaperViewInspector.h"
#import <misckit/MiscPaperView.h>

@implementation MiscPaperViewInspector

// Load the Inspector

- init
{
    char		buf[MAXPATHLEN + 1];
    id		bundle;
    
    [super init];
    
    bundle = [NXBundle bundleForClass:[MiscPaperView class]];

    if( [bundle getPath:buf forResource:"MiscPaperViewInspector" 
								ofType:"nib"] )
		[NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];

    return self;
}

// Query the object for it's attributes

- revert:sender
{
	int	aType;
	
	[gridTypeMatrix selectCellWithTag:[object gridType]];
	[gridColorWell setColor:[object gridColor]];
	[gridOriginMatrix selectCellWithTag:[object gridOrigin]];

	[gridHOffsetSlider setIntValue:[object horizontalGridSize]];
	[gridHOffsetField setIntValue:[object horizontalGridSize]];
	[gridVOffsetSlider setIntValue:[object verticalGridSize]];
	[gridVOffsetField setIntValue:[object verticalGridSize]];


	aType = [object sidelineType];
	[sidelineTypeMatrix clearSelectedCell];
	
	if( aType & Misc_PaperSidelineTop )
		[sidelineTypeMatrix selectCellWithTag:Misc_PaperSidelineTop];

	if( aType & Misc_PaperSidelineBottom )
		[sidelineTypeMatrix selectCellWithTag:Misc_PaperSidelineBottom];

	if( aType & Misc_PaperSidelineLeft )
		[sidelineTypeMatrix selectCellWithTag:Misc_PaperSidelineLeft];

	if( aType & Misc_PaperSidelineRight )
		[sidelineTypeMatrix selectCellWithTag:Misc_PaperSidelineRight];

	[sidelineTypeMatrix display];
	[sidelineColorWell setColor:[object sidelineColor]];
	[sidelineOffsetSlider setIntValue:[object sidelineOffset]];
	[sidelineOffsetField setIntValue:[object sidelineOffset]];

	return [super revert:sender];
}

- gridColorChanged:sender
{
	[object setGridColor:[gridColorWell color]];
    return [super ok:sender];
}

- gridTypeChanged:sender
{
	[object setGridType:[[sender selectedCell] tag]
				withOrigin:[object gridOrigin]];
	return [super ok:sender];
}

- gridOriginChanged:sender
{
	[object setGridType:[object gridType]
				withOrigin:[[sender selectedCell] tag]];
	return [super ok:sender];
}

- gridHOffsetChanged:sender
{
	int	offset;
	
	offset = [sender intValue];
	if( offset < 1 ) offset = 1;

	if( sender != gridHOffsetSlider )
		[gridHOffsetSlider setIntValue:offset];
	[gridHOffsetField setIntValue:offset];

	[object setGridSizeVertical:[object verticalGridSize]
					 horizontal:offset];
	return [super ok:sender];
}

- gridVOffsetChanged:sender
{
	int	offset;
	
	offset = [sender intValue];
	if( offset < 1 ) offset = 1;

	if( sender != gridVOffsetSlider )
		[gridVOffsetSlider setIntValue:offset];
	[gridVOffsetField setIntValue:offset];

	[object setGridSizeVertical:offset
					 horizontal:[object horizontalGridSize]];	
	return [super ok:sender];
}

- sidelineColorChanged:sender
{
	[object setSidelineColor:[sidelineColorWell color]];
	return [super ok:sender];
}

- sidelineTypeChanged:sender
{
	int	type = 0;
	int	i;
	id	aCell;
	
	for( i=0; i<4; i++ )
	{
		aCell = [sender cellAt:0 :i];
		if( [aCell state] == YES )	
			type += [aCell tag];
	}
	[object setSidelineType:type];
	return [super ok:sender];
}

- sidelineOffsetChanged:sender
{
	int	offset;
	
	offset = [sender intValue];
	if( offset < 0 ) offset = 0;

	if( sender != sidelineOffsetSlider )
		[sidelineOffsetSlider setIntValue:offset];
	[sidelineOffsetField setIntValue:offset];

	[object setSidelineOffset:offset];	
	return [super ok:sender];
}

- (BOOL)wantsButtons
{
	return NO;
}

@end
